/*!
 * \file tfrconfig_string.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frconfig.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_MEM_ERR);

    frfree(p_value);

}

static void __case2(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test1.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_NO_FIND);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case3(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test2.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case4(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test3.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case5(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test4.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case6(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test5.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case7(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test6.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case8(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test7.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case9(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test8.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_NO_FIND);

    frconfig_close(fp);

}

static void __case10(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test9.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case11(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test10.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"\0");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frconfig_close(fp);
    frfree(p_value);
    return;
}

static void __case12(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"size";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test4.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_NO_FIND);

    frconfig_close(fp);

}

static void __case13(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test11.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case14(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test12.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,"\0");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case15(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test13.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,(char *)"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case16(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time time time time time time time time time time time time time time time time time time time time time time time time time time time time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test14.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,(char *)"10");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case17(void)
{
    FILE *fp = NULL;
    char *p_key = NULL;
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test2.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_NO_FIND);

    frconfig_close(fp);

}

static void __case18(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test2.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_PTR_NULL(p_value);
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_NO_FIND);

    frconfig_close(fp);

}

static void __case19(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test15.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,(char *)"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

static void __case20(void)
{
    FILE *fp = NULL;
    char *p_key = (char *)"time";
    char *p_value = NULL;
    int i_ret = 0;

    fp = frconfig_open((const char *)"t_frconfig/t_frconfig_get_string/test16.txt");
    i_ret = frconfig_string(fp,p_key,&p_value);

    CU_ASSERT_STRING_EQUAL(p_value,(char *)"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    CU_ASSERT_EQUAL(i_ret,APM_FRCONFIG_SUCC);

    frfree(p_value);
    frconfig_close(fp);

}

int add_suite_frconfig_string(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frcomm frconfig_string()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);
    CU_add_test(pSuite, "case8", __case8);
    CU_add_test(pSuite, "case9", __case9);
    CU_add_test(pSuite, "case10", __case10);
    CU_add_test(pSuite, "case11", __case11);
    CU_add_test(pSuite, "case12", __case12);
    CU_add_test(pSuite, "case13", __case13);
    CU_add_test(pSuite, "case14", __case14);
    CU_add_test(pSuite, "case15", __case15);
    CU_add_test(pSuite, "case16", __case16);
    CU_add_test(pSuite, "case17", __case17);
    CU_add_test(pSuite, "case18", __case18);
    CU_add_test(pSuite, "case19", __case19);
    CU_add_test(pSuite, "case20", __case20);

    return FR_SUCC;
}
